/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.cmict.data.form.api.mapper;

import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.form.api.entity.SysCategory;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 类别表
 *
 * @author pigx code generator
 * @date 2022-03-14 11:37:08
 */
@Mapper
public interface SysCategoryMapper extends BaseMapperX<SysCategory> {

    @Update("UPDATE sys_category SET deleted = 1 WHERE id = #{id}")
    Boolean deleteSysCategory(Long id);

    @Update("update sys_category set category_order = category_order + 1 WHERE category_order >= #{categoryOrder} and deleted = 0")
    Boolean updateCategoryOrder(Integer categoryOrder);

    @Update("update sys_category set category_order = category_order - 1 WHERE category_order > #{arg0} AND category_order <= #{arg1}")
    Boolean littleToBig(Integer yuanCategoryOrder, Integer beiCategoryOrder);

    @Update("update sys_category set category_order = category_order + 1 WHERE category_order >= #{arg1} AND category_order < #{arg0} ")
    Boolean bigToLittle(Integer yuanCategoryOrder, Integer beiCategoryOrder);

    default List<SysCategory> getCategoryAll() {
        return selectList(new QueryWrapper<SysCategory>().orderByAsc("category_order"));
    }

    default SysCategory selectOne(Integer categoryOrder) {
        return selectOne(new QueryWrapper<SysCategory>().eq("category_order",categoryOrder));
    }
}
